<!--
 * @Author: wangjh wangjiahui0710@163.com
 * @Date: 2024-07-11 09:40:05
 * @LastEditors: wangjh wangjiahui0710@163.com
 * @LastEditTime: 2024-07-15 14:18:19
 * @FilePath: \cip-admin\src\pages\company\information\evaluation\components\filter.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script lang="ts" setup>
import {
	DANGER_SOURCE_LEVEL_OPTIONS,
	EVALUATE_REPORT_REPORT_TYPE_OPTIONS,
} from "@/config/enum-options";
import { injectState } from "../state";

defineOptions({ name: "Filters" });

const {
	filter,
	page: { isLoading },
} = injectState()!;

const initial = { ...toRaw(filter.value) };
const data = ref({ ...initial });

const search = () => {
	filter.value = { ...toRaw(data.value) };
};

const reset = () => {
	data.value = { ...initial };
};

const dateRange = computed({
	get() {
		if (data.value.evaluateTimeStart && data.value.evaluateTimeEnd) {
			return [data.value.evaluateTimeStart, data.value.evaluateTimeEnd];
		}
	},
	set(range) {
		data.value.evaluateTimeStart = range?.[0];
		data.value.evaluateTimeEnd = range?.[1];
	},
});
</script>

<template>
	<el-form class="filter-form" inline :model="data" :disabled="isLoading">
		<el-form-item label="危险源等级">
			<el-select-v2
				:options="[...DANGER_SOURCE_LEVEL_OPTIONS]"
				v-model="data.dangerLevel"
				clearable
				w="240px!"
			/>
		</el-form-item>
		<el-form-item label="报告类型">
			<el-select-v2
				:options="[...EVALUATE_REPORT_REPORT_TYPE_OPTIONS]"
				v-model="data.reportType"
				clearable
				w="240px!"
			/>
		</el-form-item>
		<el-form-item label="评估开始时间">
			<el-date-picker
				v-model="data.evaluateTimeStart"
				type="date"
				placeholder="请选择"
				value-format="YYYY-MM-DD HH:mm:ss"
				format="YYYY-MM-DD HH:mm:ss"
			/>
		</el-form-item>
		<el-form-item label="评估结束时间">
			<el-date-picker
				v-model="data.evaluateTimeEnd"
				type="date"
				placeholder="请选择"
				value-format="YYYY-MM-DD HH:mm:ss"
				format="YYYY-MM-DD HH:mm:ss"
			/>
		</el-form-item>
		<el-form-item>
			<el-divider direction="vertical" h="32px!" m="r-22px!" />
			<el-button type="primary" :loading="isLoading" @click="search">
				<template #icon>
					<el-icon class="i-custom:search" />
				</template>
				查询
			</el-button>
			<el-button @click="reset">
				<template #icon>
					<el-icon class="i-custom:reset" />
				</template>
				重置
			</el-button>
		</el-form-item>
	</el-form>
</template>
